package com.firstDay;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class CollectionIterator {

    //    @SuppressWarnings({"all"}) // 把警告语消失
    public static void main(String[] args) {

        Collection list = new ArrayList();

        list.add(new Book("三国演义", "罗贯中", 10.1));
        list.add(new Book("小李飞刀", "古龙", 5.1));
        list.add(new Book("红楼梦", "曹雪芹", 34.61));

        Iterator iterator = list.iterator();

        // 快捷键  while  =>  itit
        while (iterator.hasNext()) {
            Object obj = iterator.next();
            System.out.println(obj);
        }

        // ctrl + j  所有快捷键显示出来

        System.out.println("第二次遍历");
        // 当退出while循环后,这时iterator迭代器,指向最后的元素
        // iterator.next(); // NoSuchElementException
        // 如果希望再次遍历,需要重置我们的迭代器
        iterator = list.iterator();

        // 快捷键  while  =>  itit
        while (iterator.hasNext()) {
            Object obj = iterator.next();
            System.out.println(obj);
        }

    }
}
